# 根据需要对交易数据进行统计
import dateutil.utils
import matplotlib.pyplot as plt
from dateutil.utils import today
from pylab import mpl
import stock_data_deal
from datetime import date
# 从数据库中查询数据
mpl.rcParams["font.sans-serif"] = ["SimHei"]
mpl.rcParams["axes.unicode_minus"] = False

code = "600825"
# name = "新华传媒"
# code = "000100"
# name = "TCL科技"
# code = "603501"
# name = "韦尔股份"
# code = "601360"
# name = "三六零"
# code = "002230"
# name = "科大讯飞"

record_list = stock_data_deal.getDealRecord(code, date.today())
# 数据准备
x = [date.today().strftime('%Y-%m-%d')]
y1 = [sum([record.deal_num for record in record_list if (record.deal_num < 500 and record.deal_num >100  and record.deal_type == "B")])]
y2 =  [sum([record.deal_num for record in record_list if (record.deal_num < 500 and record.deal_num >100  and record.deal_type == 'S')])]

# 创建图形和轴对象
fig, ax = plt.subplots()

# 绘制折线图，并自定义样式和添加图例
ax.plot(x, y1, label='主动买入', color='red', linestyle='-', marker='o')
ax.plot(x, y2, label='主动卖出', color='green', linestyle='-', marker='o')

# 添加标题和轴标签，显示图例
ax.set_title("主力交易")
ax.set_xlabel('时间')
ax.set_ylabel('数量')
ax.legend()  # 显示图例

# 设置坐标轴范围和网格线
ax.grid(True)  # 显示网格线

# 显示图形
plt.show()


